package 同步synchonized无限等待问题;

class Service {

    

    public void methodA(Object object) { // synchronized public void methodA() {
	synchronized (object) {

	    System.out.println("methoda begin");
	    while (true) {

	    }
	}
	// System.out.println("methodA end ");
    }

    synchronized public void methodB(Object object) {
	synchronized (object) {
	    System.out.println("methodb begin");
	    System.out.println("methodb end ");
	}
    }
}

class ThreadA extends Thread {
    private Service service;

    public ThreadA(Service service) {
	super();
	this.service = service;

    }

    public void run() {
	service.methodA(new Object());
    }
}

class ThreadB extends Thread {
    private Service service;

    public ThreadB(Service service) {
	super();
	this.service = service;

    }

    public void run() {
	service.methodB(new Object());
	;
    }
}

public class Test2_53 {
    public static void main(String args[]) {

	Service service = new Service();
	ThreadA a = new ThreadA(service);
	a.setName("A");
	ThreadB b = new ThreadB(service);
	b.setName("B");
	a.start();
	b.start();

    }
}
